/*
Automatic clinic tests using a robot arm.
Copyright (C) 2010  CIC-CPC, CHU Gabriel Montpied
All other trademarks, logos and copyrights are the property
of their respective owners.

This file is part of cpc-painbot.

cpc-painbot is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

cpc-painbot is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with cpc-painbot.  If not, see <http://www.gnu.org/licenses/>.
*/
#include "commande/indproc/ascii.h"

#include <QDebug>

namespace commande {
namespace indproc {

const QRegExp Ascii::format("^\\*\\d{2}\\w{1,2}(?:[+-]\\d+)?\\r$");

Ascii * Ascii::creer(Type type)
{
    Ascii *cmd = 0;

    switch (type) {
        case LireMin:     cmd = new Ascii("V"); break;
        case ResetMin:    cmd = new Ascii("v"); break;
        case LireMax:     cmd = new Ascii("P"); break;
        case ResetMax:    cmd = new Ascii("p"); break;
        case LireTare:    cmd = new Ascii("T"); break;
        case ResetTare:   cmd = new Ascii("r"); break;
        case PrendreTare: cmd = new Ascii("t"); break;
        case LireMesure:  cmd = new Ascii("D"); break;
    }

    return cmd;
}

Ascii::Ascii(const QString &code, const QStringList &args) :
        Commande(code, args),
        adresse_(0)
{
}

QString Ascii::generer(void) const
{
    QString chaine;

    chaine = QString("*%1%2\r")
                .arg(adresse_, 2, 10, QChar('0'))
                .arg(code_);

    return chaine;
}

} // namespace indproc
} // namespace commande
